﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace student
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            NewMethod();
        }

        private void NewMethod()
        {
            string sql = "select * from Students;";
            DataTable dt = DBHelper.GetDataTable(sql);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = dt;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = "select * from Students;";
            DataTable dt = DBHelper.GetDataTable(sql);
            string name = txbname.Text;
            DataView dv = dt.DefaultView;
            dv.RowFilter = String.Format("Name like '%{0}%'", name);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = dt;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int ss = (int)(dataGridView1.SelectedRows[0].Cells[0].Value);
            string aa = string.Format("delete from Students where ID={0}", ss);
            DialogResult sg = MessageBox.Show("是否要删除？", "删除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (sg == DialogResult.OK)
            {
                bool sw = DBHelper.ExecuteNonQuery(aa);
                MessageBox.Show("删除成功");
            }
            NewMethod();
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewMethod();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
            int id = (int)(dataGridView1.SelectedRows[0].Cells[0].Value);
            
            string name = (string)(dataGridView1.SelectedRows[0].Cells[1].Value);
            
            int age = (int)(dataGridView1.SelectedRows[0].Cells[2].Value);
            
            decimal score = (decimal)(dataGridView1.SelectedRows[0].Cells[3].Value);
            
            Form3 form3 = new Form3(id,name,age,score);
            form3.Show();
        }

        private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }
    }
}
